function HandleProduce(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._user = (options && options.user) ? options.user : null;
  this._date = (options && options.date) ? options.date : null;
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._menu = (options && options.menu) ? options.menu : null;
  
  this._createElements();
};

HandleProduce.prototype._createElements = function() {
  var options, model, state, transitions = [], a, button, _self = this;
  if (this._item.state < 0) {
    this._gui.statusDiv.appendChild(document.createTextNode('Closed'));
    return;
  }
  
  model = Manage.map()[this._item.pi_model];
  for (var i = 0, il = model.states.length; i < il; i++) {
    var s = model.states[i];
    if (this._item.state == s.id) {
      state = s;
      break;
    }
  }
  for (var i = 0, il = model.transitions.length; i < il; i++) {
    var t = model.transitions[i];
    if (this._item.state == t.source.id) {
      transitions[transitions.length] = t;
    }
  }
  
  options = MiscUtils.clone(this._options);
  options.transitions = transitions;
  options.callbackFunc = function() { _self._popupBox._close();
                                      _self._callbackFunc();
                                    };
  
  if (this._item.cancelled == 0) {
    if (this._item.isCustom == 1) {
      this._gui.statusDiv.appendChild(document.createTextNode(state.title + ' (' + ((this._item.customTask.length > 18) ? this._item.customTask.substring(0, 18) + '...' : this._item.customTask)));
      if (this._item.customTask.length > 18) {
        var a = document.createElement('a');
        a.appendChild(document.createTextNode('Info'));
        a.href = '#';
        a.onclick = function() { var div = document.createElement('div');
                                 var pos = DOMUtils.findPos(this);
                                 func1 = function() { _self._popupBox._close(); };
                                 div.appendChild(MiscUtils.span(_self._item.customTask));
                                 MiscUtils.dialog(_self._popupBox, pos, div, func1, null, null);
                                 return false;
                               };
        this._gui.statusDiv.appendChild(a);
      }
      this._gui.statusDiv.appendChild(document.createTextNode(' )'));
    } else {
      this._gui.statusDiv.appendChild(document.createTextNode(state.title));
    }
//    if (this._item.events.length > 0) {
      a = document.createElement('a');
      a.style.fontSize = '10px';
      a.href = '#';
      a.appendChild(document.createTextNode('Log'));
      a.onclick = function() { var pos = DOMUtils.findPos(this);
                               var func1 = function() { _self._popupBox2._close(); };
                               var div = document.createElement('div');
                               MiscUtils.dialog(_self._popupBox2, DOMUtils.findPos(this), div, func1, null, {t: _self._item.title, width: 820, height: 100});
                               options.callbackFunc = function() { _self._popupBox2._close();
                                                                   _self._callbackFunc(pos);
                                                                 };
                               new DialogHistory(div, _self._item, options);
                               return false;
                             };
      this._gui.statusDiv.appendChild(a);
//    }

    this._gui.deadlineDiv.style.color = (this._item.deadline && ((SimpleDate.toStamp(this._item.deadline) - SimpleDate.toStamp(this._date)) / 86400) < 0) ? '#ff0000' : '#000000';
    this._gui.deadlineDiv.appendChild(document.createTextNode((this._item.deadline) ? (((((SimpleDate.toStamp(this._item.deadline) - SimpleDate.toStamp(this._date)) / 86400) <= -1) || (((SimpleDate.toStamp(this._item.deadline) - SimpleDate.toStamp(this._date)) / 86400) >= 0)) ? parseInt((SimpleDate.toStamp(this._item.deadline) - SimpleDate.toStamp(this._date)) / 86400, 10) : '-1') : ''));
       
    var count = 0;
    for (var i = 0, il = transitions.length; i < il; i++) {
      var t = transitions[i];
      if (t.validate(this._item, this._user, this._date, null)) {
        if (this._item.pi_model != Constant.MODEL_NAME_MAIL_VIDEO) {
          button = DOMUtils.createInput(null, null, 'button', t.title, null);
          button._transition = t;
          button.onclick = function() { this.disabled = true;
                                        var pos = DOMUtils.findPos(this);
                                        if (parseInt((SimpleDate.toStamp(_self._item.deadline) - SimpleDate.toStamp(_self._date)) / 86400, 10) < 0) {
                                          var div = document.createElement('div');
                                          var transition = this._transition;
                                          var button = this;
                                          var func1 = function() { if (_self._item._text == '') {
                                                                     window.alert('NOT BE EMPTY');
                                                                   } else {
                                                                     transition.operate(pos, function() { _self._callbackFunc(pos); }, _self._item, _self._user, _self._date, {extra: 'Expiration Reason: ' + _self._item._text});
                                                                     _self._popupBox2._close();
                                                                   }
                                                                 };
                                          var func2 = function() { _self._popupBox2._close(); button.disabled = false;};
                                          var func3 = function() { _self._callbackFunc(pos); };
                                          MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Expiration Reason', func: func3});
                                          new DialogInput(div, _self._item, { title: '' });
                                        } else {
                                          this._transition.operate(pos, function() { _self._callbackFunc(pos); }, _self._item, _self._user, _self._date, null);
                                        }
                                      };
          this._gui.buttonDiv.appendChild(button);
        } else {
          a = document.createElement('a');
          a.href = '?p=pageeditor&t=pagehistorytapesparcel&m=' + JSON.stringify(this._menu) + '&opts=' + JSON.stringify({ p: this._item.id });
          a.appendChild(document.createTextNode('Receive'));
          this._gui.buttonDiv.appendChild(a);
        }
        count++;
      }
    }
    
    if (count == 0 && transitions.length != 0) {
      if (this._item.isCustom == 1) {
        this._gui.buttonDiv.appendChild(document.createTextNode(this._item.user_account));
      } else {
        this._gui.buttonDiv.appendChild(document.createTextNode(((transitions[0].position.charAt(0) == '#') ? transitions[0].position.substring(1) : transitions[0].position) + ''));
      }
    }
  } else {
    this._gui.statusDiv.appendChild(document.createTextNode('Cancelled'));
  }
  
  if (this._item.pi_model == Constant.MODEL_NAME_MAIL) {
    a = document.createElement('a');
    a.href = '?p=pagefactory&t=pagehistorymailinformation&m=' + JSON.stringify({ a: 1, b: 1, c: 2}) + '&opts=' + JSON.stringify({ p: _self._item.id });
    a.appendChild(document.createTextNode('Review'));
    this._gui.buttonDiv.appendChild(a);
  }
};